package org.leetcode.middle.leetcode513;

import org.leetcode.TreeNode;

import java.util.LinkedList;
import java.util.Queue;
import java.util.Stack;

public class Solution
{
    public int findBottomLeftValue(TreeNode root) {

        Queue<TreeNode> queue = new LinkedList<>();
        int res =0;
        queue.add(root);
        while (!queue.isEmpty())
        {
            int size = queue.size();
            int temp = size;
            while (size>0)
            {
                TreeNode tempNode = queue.poll();
                if (size==temp)  res=tempNode.val;

                if (tempNode.left!=null) queue.add(tempNode.left);

                if (tempNode.right!=null) queue.add(tempNode.right);
                size--;
            }
        }

        return res;
    }


}
